﻿using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using BySoft.Server.Business;
using BySoft.Server.Common.Entity;
using BySoft.Server.Common.Enum;
using BySoft.Web.Utility;
using BySoft.Server.Consts;
using BySoft.Server.Common;
using BySoft.Web.Controls;

namespace BySoft.Web.Site.ComPage
{
    public partial class QueryUser : BasePage
    {
        #region 变量定义
        int m_count = 0;
        public string m_dispaly = "none";
        private DataTable dtUserID
        {
            get
            {
                if (Session["UserID"] != null)
                {
                    DataTable dt = (DataTable)Session["UserID"];
                    return dt;
                }
                else
                {
                    DataTable dt = CreateData();
                    return dt;
                }
            }
            set
            {
                Session["UserID"] = value;
            }
        }

        private DataTable dtUserIDSteady
        {
            get
            {
                if (Session["UserIDSteady"] != null)
                {
                    DataTable dt = (DataTable)Session["UserIDSteady"];
                    return dt;
                }
                else
                {
                    DataTable dt = CreateData();
                    return dt;
                }
            }
            set
            {
                Session["UserIDSteady"] = value;
            }
        }
        #endregion

        #region 属性定义

        #endregion

        #region 获取页面传参

        #endregion

        #region 初始化及绑定控件
        private void BindUserType()
        {
            UIHelper.BindSortList(ddlUserType, BaseEnum.UserTypeList2());
            UIHelper.InsertFirstItem(ddlUserType);
        }
        private void BindData(int pageIndex)
        {
            //DataTable dtUser = SysUser.GetUserList(txtUserID.Text.Trim(), txtUserName.Text.Trim(), ddlEmployeeType.SelectedItem.Value,
            //    stxtAgent.Value.Trim(), ddlJobTitle.SelectedItem.Value, ddlStatus.SelectedItem.Value,
            //    pageIndex, pcData.PageSize,out m_count);
            DataTable dtUser = SysUser.GetAllUserInfo(ddlUserType.SelectedItem.Value, txtUserName.Text.Trim(), txtUserID.Text, ddlStatus.SelectedItem.Value,
               pageIndex, pcData.PageSize, out m_count);
            pcData.RecordCount = m_count;
            if (dtUser.Rows.Count > 0)
            {
                grdResult.DataSource = dtUser;
                grdResult.DataBind();
                //pcData.Visible = true;

                pcData.CurrentIndex = pageIndex;
            }
            else
            {
                UIHelper.BindEmptyGridView(grdResult, dtUser);
                //pcData.Visible = false;
            }
        }
        #endregion

        #region 控件事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["DispatchUser"] = null;
                dtUserID = null;
                BindUserType();
                UIHelper.InsertFirstItem(ddlStatus);
                BindData(0);
            }
        }



        protected void btnSearch_Click(object sender, EventArgs e)
        {
            dtUserID = null;
            BindData(0);
        }

        protected void pcData_PageIndexClick(object sender, PageIndexClickEventArgs e)
        {
            AddPro();
            BindData(e.PageIndex);
        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            string sReturn = "";
            foreach (GridViewRow gvr in grdResult.Rows)
            {
                Label lblUSERID = gvr.FindControl("lblUSERID") as Label;
                Label lblUSERNAME = gvr.FindControl("lblUSERNAME") as Label;
                if (gvr.RowType == DataControlRowType.DataRow)
                {
                    if (((RadioButton)gvr.FindControl("rbSelect")).Checked)
                    {
                        //产品编号，产品名称，图号，版本号，客户编号，客户名称
                        sReturn = HttpUtility.UrlEncode(lblUSERID.Text + "," +
                            lblUSERNAME.Text ,System.Text.Encoding.UTF8);
                        break;
                    }
                }
            }
            Session["DispatchUser"] = sReturn;
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>setCookie(dialogReturn_key,'" + sReturn + "',1);CloseTopDialog();</script>");
        }

        protected void grdResult_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            
        }

        protected void grdResult_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                RadioButton rb = (RadioButton)e.Row.FindControl("rbSelect");
                rb.Attributes.Add("onclick", "judge(this)");
            }
        }
        #endregion

        #region 本地方法
        public string SetFormat(object param)
        {
            return HttpUtility.UrlEncode(param.ToString());
        }

        private DataTable CreateData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ID", typeof(string));
            dt.Columns.Add("UserName");
            return dt;
        }

        private void AddPro()
        {
         
        }
        #endregion

        #region 校验方法
        #endregion

    }
}
